<?php
defined('IN_IA') or exit('Access Denied');

/**
 * 执行类
 * @param $_className
 * @return mixed
 */
function execClass($_className)
{
    return new $_className();
}

/**
 * 执行方法
 * @param $_class
 * @param $_methodName
 */
function execMethod($_class,$_methodName)
{
    $_class->$_methodName();
}

class kuyuan_stallModuleSite extends WeModuleSite {
    public function doWebApi()
    {
        $this->api();
    }

    public function doMobileApi()
    {
        $this->api();
    }

    private function api()
    {
        require MODULE_ROOT.'/vendor/autoload.php';
        global $_GPC;
        //$this->ajax();
        if(isset($_GPC['pages']) && !empty($_GPC['pages'])){
            if(!is_file(MODULE_ROOT.'/action/'.ucwords($_GPC['pages']).'.php')){
                exit(ucwords($_GPC['pages']).'.php文件不存在');
            }
            $_action = call_user_func('execClass','App\\'.ucwords($_GPC['pages']));
            if(isset($_GPC['doing']) && !empty($_GPC['doing'])){
                $_methodName = $_GPC['doing'];
            }else{
                $_methodName = 'index';
            }
            if(!method_exists($_action,$_methodName)){
                exit($_methodName.'()方法不存在');
            }
            call_user_func('execMethod',$_action,$_methodName);
        }
    }

    /**
     * 外部ajaxq请求
     */
    private function ajax()
    {
        header("Access-Control-Allow-Origin:*");
        header("Access-Control-Allow-Origin: *");
        header('Access-Control-Allow-Headers:Authorization');
        header("Access-Control-Allow-Methods: GET, POST, DELETE");
        header("Access-Control-Allow-Credentials: true");
        header("Access-Control-Allow-Headers: Content-Type, X-Requested-With, Cache-Control,Authorization");
    }


}
